package com.yswl.pri.guide;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yswl.pri.R;
import com.yswl.pri.common.ToolbarMFragment;

import yswl.com.klibrary.browser.BrowserActivity;
import yswl.com.klibrary.util.AppCacheCleanManager;
import yswl.com.klibrary.util.MAppInfoUtil;
import yswl.com.klibrary.util.MKeyBoardUtils;
import yswl.com.klibrary.util.ToastUtil;

/**
 * Created by kangpAdministrator on 2018/5/8 0008.
 * Emial kangpeng@yunhetong.net
 */

public class AboutFragment extends ToolbarMFragment implements View.OnClickListener {
    private static final String TAG = AboutFragment.class.getSimpleName();

    @Override
    protected String getToolbarTitle() {
        return "关于";
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_about, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        view.findViewById(R.id.tv_about).setOnClickListener(this);
        view.findViewById(R.id.tv_addqq).setOnClickListener(this);
        view.findViewById(R.id.tv_contact).setOnClickListener(this);
        view.findViewById(R.id.tv_clear).setOnClickListener(this);
        ((TextView) view.findViewById(R.id.tv_version)).setText(MAppInfoUtil.getVersionName());

    }

    public static void playAudio(Context context, String audioPath) {
        Intent mIntent = new Intent();
        mIntent.setAction(android.content.Intent.ACTION_VIEW);
        Uri uri = Uri.parse(audioPath);
        mIntent.setDataAndType(uri, "audio/mp3");
        context.startActivity(mIntent);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        menu.clear();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_about:
                String url = "file:///android_asset/about.html";
                BrowserActivity.start("免责声明", url, getMActivity());
                break;
            case R.id.tv_addqq:
                AlertDialog dialog = new AlertDialog.Builder(getMActivity()).setMessage("追剧不用愁，全网电影电视剧一网打尽，群里不定期发布最新电影电视剧资源  \n " +
                        "群   号： 774953729").setTitle("全网vip视频免费观影").setNegativeButton("确 定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        MKeyBoardUtils.copy("774953729", getMActivity());
                        ToastUtil.showToast("已复制QQ群号");

                    }
                }).create();
                dialog.setCanceledOnTouchOutside(false);
                dialog.show();
                break;
            case R.id.tv_contact:
                AlertDialog dialog2 = new AlertDialog.Builder(getMActivity()).setMessage("欢迎志同道合的道友加入,\n 联系邮箱：2544076544@qq.com").setTitle("联系方式").setNegativeButton("确 定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        Uri uri = Uri.parse("mailto:2544076544@qq.com");
//                        String[] email = {"2544076544@qq.com"};
//                        Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
//                        intent.putExtra(Intent.EXTRA_CC, email); // 抄送人
//                        intent.putExtra(Intent.EXTRA_SUBJECT, "追剧小助手"); // 主题
//                        intent.putExtra(Intent.EXTRA_TEXT, "追剧小助手"); // 正文
//                        startActivity(Intent.createChooser(intent, "选择如下方式发送邮件"));
                        dialog.dismiss();
                    }
                }).create();
                dialog2.show();
                break;
            case R.id.tv_clear:
                AppCacheCleanManager.cleanApplicationData2(getActivity(), new String[]{});
                ToastUtil.showToast("已清除");
                break;
        }
    }
}
